package com.company.cloud.base.modules.mgr.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.company.cloud.base.modules.cache.models.BizTypeModel;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.redis.service.RedisUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/mgr/base/cache")
@Api(tags = "Mgr_Base_缓存管理")
public class CacheMgrController {

    @Autowired
    private RedisUtils redisUtils;

    @GetMapping("/getRedis")
    @ApiOperation(value = "查询缓存", response = BizTypeModel.class)
    public BaseResult getRedis(@RequestParam("redisKey") String redisKey) {
        if (redisUtils.hasKey(redisKey)) {
            return BaseResult.ok(redisUtils.get(redisKey));
        } else {
            return BaseResult.ok();
        }
    }

    @GetMapping("/delRedis")
    @ApiOperation(value = "删除缓存", response = BizTypeModel.class)
    public BaseResult delRedis(@RequestParam("redisKey") String redisKey) {
        redisUtils.delete(redisKey);
        return BaseResult.ok();
    }

//    @GetMapping("/redisyuanzi")
//    @ApiOperation(value = "缓存原子", response = BizTypeModel.class)
//    public BaseResult redisyuanzi(@RequestParam("redisKey") String redisKey) {
//        //redisUtils.set(redisKey, 10);
//        System.out.println("值:" + redisUtils.get(redisKey));
//        redisUtils.increment(redisKey, (long)1);
//        System.out.println("值:" + redisUtils.get(redisKey));
//        redisUtils.increment(redisKey, (long)-2);
//        System.out.println("值:" + redisUtils.get(redisKey));
//        return BaseResult.ok();
//    }
}
